package com.yz.mcd.view;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.yz.mcd.R;

/**
 * 使用slidingmenu
 * 1.引入slidingmenu的库
 * 2.继承SlidingActivity
 * 3.onCreate改成public
 * 4.调用相关api
 *
 *
 * Created by Maverick on 2017/4/26.
 */

public class Ac_main extends SlidingFragmentActivity{

    private static final String TAG_LEFT_MENU = "TAG_LEFT_MENU";
    private static final String TAG_CONTENT = "TAG_CONTENT";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题
        //必须在setContentView之前调用
        setContentView(R.layout.activity_main);

        //设置侧边栏
        setBehindContentView(R.layout.left_menu);

        SlidingMenu slidingMenu = getSlidingMenu();

//        //设置右侧侧边栏
//        slidingMenu.setSecondaryMenu(R.layout.right_menu);
//        slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);//设置模式，左右都有侧边栏

        //设置全屏触摸
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

        //设置侧边栏宽度
        slidingMenu.setBehindOffset(200);//设置屏幕预留宽度,单位应该是像素

        initFragment();
    }

    /**
     * 初始化fragment对象
     *
     */
    private void initFragment(){
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();//开启事务
        transaction.replace(R.id.fl_left_menu,new LeftMenuFragment(),TAG_LEFT_MENU);//用fragment替换帧布局,参1：帧布局容器的id;参2：是要替换的fragment;参3：标记
        transaction.replace(R.id.fl_main,new ContentFragment(),TAG_CONTENT);
        transaction.commit();//提交事务

//        Fragment fragment = fm.findFragmentByTag(TAG_LEFT_MENU);//根据标记找到fragment对象
    }

}
